Imports System.Data.SqlClient
Public Class cls_liquidaciondetalle_

    Implements ICloneable

#Region "Variables ..."
    Private int_idliquidaciondetalle As Integer = 0
    Private int_idclientearticulo As Integer = 0
    Private dbl_descuentoP As Double = 0
    Private dbl_descuentoV As Double = 0
    Private dbl_recargoP As Double = 0
    Private dbl_recargoV As Double = 0
    Private dbl_ultimovalor As Double = 0
    Private dbl_nuevovalor As Double = 0
    Private int_idliquidacion As Integer = 0

    Private obj_clientearticulo As cls_clientearticulo_

    Private col_Items As Collections.Generic.List(Of cls_liquidaciondetalle_) = Nothing
#End Region

#Region "Propiedades ..."
    Property idliquidaciondetalle() As Integer
        Get
            idliquidaciondetalle = int_idliquidaciondetalle
        End Get
        Set(ByVal value As Integer)
            int_idliquidaciondetalle = value
        End Set
    End Property
    Property idclientearticulo() As Integer
        Get
            idclientearticulo = int_idclientearticulo
        End Get
        Set(ByVal value As Integer)
            int_idclientearticulo = value
        End Set
    End Property
    Property descuentoP() As Double
        Get
            descuentoP = dbl_descuentoP
        End Get
        Set(ByVal value As Double)
            dbl_descuentoP = value
        End Set
    End Property
    Property descuentoV() As Double
        Get
            descuentoV = dbl_descuentoV
        End Get
        Set(ByVal value As Double)
            dbl_descuentoV = value
        End Set
    End Property
    Property recargoP() As Double
        Get
            recargoP = dbl_recargoP
        End Get
        Set(ByVal value As Double)
            dbl_recargoP = value
        End Set
    End Property
    Property recargoV() As Double
        Get
            recargoV = dbl_recargoV
        End Get
        Set(ByVal value As Double)
            dbl_recargoV = value
        End Set
    End Property
    Property ultimovalor() As Double
        Get
            ultimovalor = dbl_ultimovalor
        End Get
        Set(ByVal value As Double)
            dbl_ultimovalor = value
        End Set
    End Property
    Property nuevovalor() As Double
        Get
            nuevovalor = dbl_nuevovalor
        End Get
        Set(ByVal value As Double)
            dbl_nuevovalor = value
        End Set
    End Property
    Property idliquidacion() As Integer
        Get
            idliquidacion = int_idliquidacion
        End Get
        Set(ByVal value As Integer)
            int_idliquidacion = value
        End Set
    End Property
    Property clientearticulo_() As cls_clientearticulo_
        Get
            If IsNothing(obj_clientearticulo) Then
                obj_clientearticulo = New cls_clientearticulo_
                If Not obj_clientearticulo.Buscar(idclientearticulo) Then
                    obj_clientearticulo = Nothing
                End If
            End If
            clientearticulo_ = obj_clientearticulo
        End Get
        Set(ByVal value As cls_clientearticulo_)
            obj_clientearticulo = value
        End Set
    End Property
    Property Items() As Collections.Generic.List(Of cls_liquidaciondetalle_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_liquidaciondetalle_))
            col_Items = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_liquidaciondetalle_)
        While obj_Reader.Read()
            Dim Elemento As New cls_liquidaciondetalle_
            Elemento.int_idliquidaciondetalle = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idliquidaciondetalle")))

            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idclientearticulo"))) = False Then
                Elemento.int_idclientearticulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idclientearticulo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP"))) = False Then
                Elemento.dbl_descuentoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoV"))) = False Then
                Elemento.dbl_descuentoV = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoV")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP"))) = False Then
                Elemento.dbl_recargoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoV"))) = False Then
                Elemento.dbl_recargoV = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoV")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("ultimovalor"))) = False Then
                Elemento.dbl_ultimovalor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("ultimovalor")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nuevovalor"))) = False Then
                Elemento.dbl_nuevovalor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nuevovalor")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idliquidacion"))) = False Then
                Elemento.int_idliquidacion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idliquidacion")))
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        int_idliquidaciondetalle = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idliquidaciondetalle")))

        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idclientearticulo"))) = False Then
            int_idclientearticulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idclientearticulo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP"))) = False Then
            dbl_descuentoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoV"))) = False Then
            dbl_descuentoV = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoV")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP"))) = False Then
            dbl_recargoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoV"))) = False Then
            dbl_recargoV = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoV")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("ultimovalor"))) = False Then
            dbl_ultimovalor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("ultimovalor")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nuevovalor"))) = False Then
            dbl_nuevovalor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nuevovalor")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idliquidacion"))) = False Then
            int_idliquidacion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idliquidacion")))
        End If
    End Sub

    Public Sub Nuevo(Optional ByVal ObtenerID As Boolean = False)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__Nuevo"
                .Parameters.Add("@idclientearticulo", SqlDbType.Int).Value = int_idclientearticulo
                .Parameters.Add("@descuentoP", SqlDbType.Decimal).Value = dbl_descuentoP
                .Parameters.Add("@descuentoV", SqlDbType.Decimal).Value = dbl_descuentoV
                .Parameters.Add("@recargoP", SqlDbType.Decimal).Value = dbl_recargoP
                .Parameters.Add("@recargoV", SqlDbType.Decimal).Value = dbl_recargoV
                .Parameters.Add("@ultimovalor", SqlDbType.Decimal).Value = dbl_ultimovalor
                .Parameters.Add("@nuevovalor", SqlDbType.Decimal).Value = dbl_nuevovalor
                .Parameters.Add("@idliquidacion", SqlDbType.Int).Value = int_idliquidacion
                .ExecuteNonQuery()
            End With
            If ObtenerID Then
                CargarUltimo()
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Crear el registro de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__Modificar"
                .Parameters.Add("@idliquidaciondetalle", SqlDbType.Int).Value = int_idliquidaciondetalle
                .Parameters.Add("@idclientearticulo", SqlDbType.Int).Value = int_idclientearticulo
                .Parameters.Add("@descuentoP", SqlDbType.Decimal).Value = dbl_descuentoP
                .Parameters.Add("@descuentoV", SqlDbType.Decimal).Value = dbl_descuentoV
                .Parameters.Add("@recargoP", SqlDbType.Decimal).Value = dbl_recargoP
                .Parameters.Add("@recargoV", SqlDbType.Decimal).Value = dbl_recargoV
                .Parameters.Add("@ultimovalor", SqlDbType.Decimal).Value = dbl_ultimovalor
                .Parameters.Add("@nuevovalor", SqlDbType.Decimal).Value = dbl_nuevovalor
                .Parameters.Add("@idliquidacion", SqlDbType.Int).Value = int_idliquidacion
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Modificar el registro de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Eliminar(ByVal idliquidaciondetalle As Integer)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__Eliminar"
                .Parameters.Add("@idliquidaciondetalle", SqlDbType.Int).Value = idliquidaciondetalle
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Eliminar el registro de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal idliquidaciondetalle As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__Buscar"
                .Parameters.Add("@idliquidaciondetalle", SqlDbType.Int).Value = idliquidaciondetalle
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al Buscar el registro de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function BuscarXidliquidacionXidclientearticulo(ByVal prm_idliquidacion As Integer, ByVal prm_idclientearticulo As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            BuscarXidliquidacionXidclientearticulo = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__BuscarXidliquidacionXidclientearticulo"
                .Parameters.Add("@idliquidacion", SqlDbType.Int).Value = prm_idliquidacion
                .Parameters.Add("@idclientearticulo", SqlDbType.Int).Value = prm_idclientearticulo
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                BuscarXidliquidacionXidclientearticulo = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al BuscarXidliquidacionXidclientearticulo el registro de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Sub CargarUltimo()
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__CargarUltimo"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarUltimo registro de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Sub

    Public Function CargarTodos() As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__CargarTodos"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarTodos los registros de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function CargarXidliquidacion(ByVal prm_idliquidacion As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXidliquidacion = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "liquidaciondetalle__CargarXidliquidacion"
                .Parameters.Add("@idliquidacion", SqlDbType.Int).Value = prm_idliquidacion
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXidliquidacion = True
            End If
        Catch ex As SqlClient.SqlException
            MessageBox.Show("Error al CargarXidliquidacion los registros de liquidaciondetalle_." & Chr(13) & _
            "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
            "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
            "Descripción: " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function
    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_liquidaciondetalle_Clon As New cls_liquidaciondetalle_
        obj_liquidaciondetalle_Clon.int_idliquidaciondetalle = Me.int_idliquidaciondetalle
        obj_liquidaciondetalle_Clon.int_idclientearticulo = Me.int_idclientearticulo
        obj_liquidaciondetalle_Clon.dbl_descuentoP = Me.dbl_descuentoP
        obj_liquidaciondetalle_Clon.dbl_descuentoV = Me.dbl_descuentoV
        obj_liquidaciondetalle_Clon.dbl_recargoP = Me.dbl_recargoP
        obj_liquidaciondetalle_Clon.dbl_recargoV = Me.dbl_recargoV
        obj_liquidaciondetalle_Clon.dbl_ultimovalor = Me.dbl_ultimovalor
        obj_liquidaciondetalle_Clon.dbl_nuevovalor = Me.dbl_nuevovalor
        obj_liquidaciondetalle_Clon.int_idliquidacion = Me.int_idliquidacion
        obj_liquidaciondetalle_Clon.col_Items = Me.col_Items
        Return obj_liquidaciondetalle_Clon
    End Function

End Class


